package com.oo.app.ui.main.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.oo.app.R;
import com.oo.app.ui.main.activity.boy.HomeBoyActivity;

import java.util.List;

import butterknife.BindView;

/**
 * Created by Wasabeef on 2015/01/03.
 */
public class GrabChatAdapter extends RecyclerView.Adapter<GrabChatAdapter.ViewHolder> {

  private Context mContext;
  private List<String> mDataSet;

  public GrabChatAdapter(Context context, List<String> dataSet) {
    mContext = context;
    mDataSet = dataSet;
  }

  @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View v = LayoutInflater.from(mContext).inflate(R.layout.item_grab_chat, parent, false);
    return new ViewHolder(v);
  }

  @Override public void onBindViewHolder(ViewHolder holder, int position) {
//    Picasso.with(mContext).load(R.drawable.chip).into(holder.image);
    holder.text.setText(mDataSet.get(position));
    RequestOptions options = new RequestOptions()
            .diskCacheStrategy(DiskCacheStrategy.ALL);
    Glide.with(mContext).load(R.mipmap.home_male_btn_chat_animation)
            .apply(options).into(holder.ivGif);
  }

  @Override public int getItemCount() {
    return mDataSet.size();
  }

  public void remove(int position) {
    mDataSet.remove(position);
    mDataSet.clear();
    notifyItemRemoved(position);
  }

  public void clear() {
    mDataSet.clear();
    notifyDataSetChanged();
  }

  public void add(String text, int position) {
    mDataSet.add(position, text);
    notifyItemInserted(position);
  }

  static class ViewHolder extends RecyclerView.ViewHolder {

    public ImageView image;
    public TextView text;
    public ImageView ivGif;

    public ViewHolder(View itemView) {
      super(itemView);
      ivGif = (ImageView) itemView.findViewById(R.id.iv_gif);
      text = (TextView) itemView.findViewById(R.id.tv_name);
    }
  }
}
